package nl.myhealth.app.myhealthapp.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import nl.myhealth.app.myhealthapp.Measurement.PressureMeasurment;
import nl.myhealth.app.myhealthapp.Measurement.PulseMeasurement;
import nl.myhealth.app.myhealthapp.R;

/**
 * Created by Stephan E G Veenstra on 28-9-2014.
 */
public class MeasurementAdapter<T> extends ArrayAdapter<T> {


    public MeasurementAdapter(Context context)
    {
        super(context,android.R.layout.simple_list_item_1);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = null;
        Object measurementObj = getItem(position);
        if(measurementObj instanceof PulseMeasurement) {
            rowView = inflater.inflate(R.layout.list_item_pulse, parent, false);
            TextView measurement = (TextView) rowView.findViewById(R.id.list_item_pulse_measurement);
            TextView timestamp = (TextView) rowView.findViewById(R.id.list_item_pulse_timestamp);

            measurement.setText(((PulseMeasurement) measurementObj).getPulse() + "");
            timestamp.setText(((PulseMeasurement) measurementObj).getTimestamp().toString());
        }
        else if(measurementObj instanceof PressureMeasurment)
        {
            rowView = inflater.inflate(R.layout.list_item_pressure, parent, false);
            TextView systolic = (TextView) rowView.findViewById(R.id.list_item_pressure_systolic);
            TextView diastolic = (TextView) rowView.findViewById(R.id.list_item_pressure_diastolic);
            TextView timestamp = (TextView) rowView.findViewById(R.id.list_item_pressure_timestamp);

            systolic.setText(((PressureMeasurment) measurementObj).getSystolic() + "");
            diastolic.setText(((PressureMeasurment) measurementObj).getDiastolic() + "");
            timestamp.setText(((PressureMeasurment) measurementObj).getTimestamp().toString());
        }
        return rowView;
    }
}
